﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;

namespace _20200618.UC
{
    public partial class BookManagement : UserControl
    {

        private BookBLL bll; //定义书籍业务逻辑访问类
        private DataSet ds;//定义数据集 用于填充列表

        public BookManagement()
        {
            InitializeComponent();
            bll = new BookBLL(); //实例化业务逻辑对象
        }
        private void GetBookList()
        {
            ds=bll.GetBookList();
            dataGridView1.DataSource = ds.Tables[0]; //将数据集绑定到dataGridView1控件

        }
        //清除文本输入框
        private void TextBoxClean(Control controlName)
        {
            foreach(Control control in this.Controls)
            {
                if (control is TextBox)
                    ((TextBox)control).Clear();
            }
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        //撤销
        private void button1_Click(object sender, EventArgs e)
        {
            //TextBoxClean();
            this.textBox1.Clear();
            this.textBox2.Clear();
            this.textBox3.Clear();
            this.textBox4.Clear();
            this.textBox5.Clear();
            this.textBox6.Clear();
            this.textBox9.Clear();
            this.textBox10.Clear();
            this.textBox11.Clear();
        }

        private void BookManagement_Load(object sender, EventArgs e)
        {
            GetBookList();
        }

        private void UCBooksbtnSearch_Click(object sender, EventArgs e)
        {
            string inputString = this.UCBooktxtSearchStr.Text.Trim(); //捕获用户输入的值

            if (String.IsNullOrEmpty(inputString)) //如果控件内容为空
            {
                MessageBox.Show("请输入需要查找的内容！", "系统提示：");
                this.UCBooktxtSearchStr.Focus(); //光标焦点
                return;
            }

            if (this.UCBookcbSelected.SelectedIndex == -1)
            {
                MessageBox.Show("请选择搜索类型！", "系统提示：");
                return;
            }

            if (this.UCBookcbSelected.SelectedIndex == 0) //搜索bookID
            {
                ds = bll.GetBookListByBookID(inputString);
                dataGridView1.DataSource = ds.Tables[0];
            }

            if (this.UCBookcbSelected.SelectedIndex == 1)//搜索bookName
            {
                ds = bll.GetBookListByBookName(inputString);
                dataGridView1.DataSource = ds.Tables[0];
            }

            if (this.UCBookcbSelected.SelectedIndex == 2) //搜索bookID
            {
                ds = bll.GetBookListByPublisher(inputString);
                dataGridView1.DataSource = ds.Tables[0];
            }

            if (this.UCBookcbSelected.SelectedIndex == 3) //搜索bookID
            {
                ds = bll.GetBookListByAuthor(inputString);
                dataGridView1.DataSource = ds.Tables[0];
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
